Description:
Use a switch
statement instead of several nested if-else statements
testing the same expression.
You can set the option, Minimal number of cases, in the audit's properties to define the minimal size of the
if-else construct that RIEWS will suggest to convert to a switch
.
Incorrect:
if (obj.getObjectKind() == TABLE) {
...
} else if (obj.getObjectKind() == TREE) {
...
} else if (obj.getObjectKind() == TAB_FOLDER) {
...
} else if (obj.getObjectKind() == TOOL_BAR) {
...
}
Correct:
switch (obj.getObjectKind()) {
case TABLE:
...
break;
case TREE:
...
break;
case TAB_FOLDER:
...
break;
case TOOL_BAR:
...
break;
}